@echo off
REM Windows打包脚本
chcp 65001 > nul

echo ====================================
echo Apple固件监控系统 - 打包脚本
echo ====================================
echo.

REM 设置变量
set PROJECT_NAME=iphone-firmware-monitor
set VERSION=2.1
set DATE=%date:~0,4%%date:~5,2%%date:~8,2%
set PACKAGE_NAME=%PROJECT_NAME%_v%VERSION%_%DATE%.zip

echo 打包信息:
echo   项目: %PROJECT_NAME%
echo   版本: %VERSION%
echo   日期: %DATE%
echo   文件: %PACKAGE_NAME%
echo.

REM 创建临时目录
set TMP_DIR=%TEMP%\%PROJECT_NAME%_build
if exist "%TMP_DIR%" rd /s /q "%TMP_DIR%"
mkdir "%TMP_DIR%"

echo [1/5] 复制项目文件...

REM 复制文件
copy firmware_monitor.py "%TMP_DIR%\" > nul
copy requirements.txt "%TMP_DIR%\" > nul
copy README.md "%TMP_DIR%\" > nul
copy CHANGELOG.md "%TMP_DIR%\" > nul

REM 复制目录
xcopy /E /I /Q config "%TMP_DIR%\config" > nul
xcopy /E /I /Q docs "%TMP_DIR%\docs" > nul
xcopy /E /I /Q scripts "%TMP_DIR%\scripts" > nul

REM 创建日志目录
mkdir "%TMP_DIR%\logs"

echo [2/5] 排除不必要文件...

REM 删除临时文件
del /s /q "%TMP_DIR%\*.pyc" 2>nul
for /d /r "%TMP_DIR%" %%d in (__pycache__) do @if exist "%%d" rd /s /q "%%d"
del "%TMP_DIR%\.env" 2>nul
del "%TMP_DIR%\firmware_status.json" 2>nul

echo [3/5] 创建部署说明...

REM 创建部署说明
(
echo Apple固件监控系统 - 部署说明
echo ==================================
echo.
echo 1. 上传到服务器
echo    使用WinSCP或FileZilla上传zip文件
echo.
echo 2. 解压
echo    unzip %PACKAGE_NAME%
echo    cd %PROJECT_NAME%
echo.
echo 3. 安装环境
echo    python3 -m venv venv
echo    source venv/bin/activate
echo    pip install -r requirements.txt
echo.
echo 4. 配置
echo    cp config/config.example.env .env
echo    nano .env
echo.
echo 5. 测试运行
echo    python firmware_monitor.py --once
echo.
echo 6. 配置服务
echo    详见 docs/DEPLOYMENT_GUIDE.md
echo.
echo 更多信息请查看：
echo - README.md - 项目说明
echo - docs/DEPLOYMENT_GUIDE.md - 详细部署指南
echo - CHANGELOG.md - 更新日志
echo.
) > "%TMP_DIR%\DEPLOY.txt"

echo [4/5] 打包压缩...

REM 使用PowerShell压缩
powershell -command "Compress-Archive -Path '%TMP_DIR%\*' -DestinationPath '%PACKAGE_NAME%' -Force"

echo [5/5] 清理临时文件...
rd /s /q "%TMP_DIR%"

echo.
echo ====================================
echo 打包完成！
echo ====================================
echo.
echo 文件位置: %CD%\%PACKAGE_NAME%
echo.
dir /B %PACKAGE_NAME%
echo.
echo 下一步:
echo   1. 使用FTP/SCP工具上传到服务器
echo      推荐: WinSCP, FileZilla
echo.
echo   2. 服务器上解压
echo      unzip %PACKAGE_NAME%
echo.
echo   3. 查看部署说明
echo      cat DEPLOY.txt
echo.

pause

